/** Double-include prevention */
#if defined _mynatives_included_
  #endinput
#endif
#define _mynatives_included_

#define WeaponCap 125

new RegisteredWeapons = 0;

new String:WeaponReplaceClass[WeaponCap][32];
new String:WeaponName[WeaponCap][32];

new WeaponViewModel[WeaponCap];
new WeaponWorldModel[WeaponCap];

new Handle:g_WeaponGiven;
new Handle:g_WeaponRemoved;
new Handle:g_WeaponFired;
new Handle:g_WeaponDamaged;
new Handle:g_WeaponKilled;

/**
 * @brief When a custom weapon has been given to the player
 *
 * @param		Client		A Player
 * @param		Integer		WeaponID
 * @noreturn
 */
forward WXF_OnWeaponGiven(Client, WeaponID);

/**
 * @brief When a custom weapon has been removed from the player
 *
 * @param		Client		A Player
 * @param		Integer		WeaponID
 * @noreturn
 */
forward WXF_OnWeaponRemoved(Client, WeaponID);

/**
 * @brief When a custom weapon has been fired.
 *
 * @param		Client		A Player
 * @param		Integer		WeaponID
 */
forward WXF_OnWeaponFired(Client, WeaponID);

/**
 * @brief Registers a custom Weapon and Returns it's index.
 *
 * @param		String			WeaponToReplace
 * @param		String			WeaponName
 * @return		Integer			WeaponID
 */
native WX_RegisterWeapon(const String:replace[], const String:name[]);

/**
 * @brief	Sets the weapons View/World Model.
 *
 * @param		Integer			WeaponID
 * @param		String			Path
 * @noreturn
 */
native WX_SetWeaponViewModel(WeaponID, const String:path[]);
native WX_SetWeaponWorldModel(WeaponID, const String:path[]);

/**
 * @brief	Returns Model Index.
 *
 * @param 		Integer		WeaponID
 * @return		Integer		ModelIndex
 */
native WX_GetWeaponViewModel(WeaponID);
native WX_GetWeaponWorldModel(WeaponID);

/**
 * @brief Gets Weapon Name by its ID.
 *
 * @param 		Integer   	The Ability
 * @param		Integer		WeaponID
 * @return		String		WeaponName
 */
native WX_GetWeaponName(Weapon, String:buffer[]);

/**
 * @brief Returns how many registered weapons there are.
 *
 * @return Number of registered Weapons
 */
native WX_RegisteredWeapons();

native WX_GetWeaponReplaceClass(WeaponID, String:buffer[]);
native WX_CallForward(ForwardID, Client, WeaponID);
native WX_CallForward3(ForwardID, Client, WeaponID, Victim);

forward WXF_OnWeaponGiven(Client, WeaponID);
forward WXF_OnAbilityRemoved(Client, WeaponID);
forward WXF_OnWeaponFired(Client, WeaponID);
forward WXF_OnWeaponDamaged(Client, WeaponID, Victim);
forward WXF_OnWeaponKilled(Client, WeaponID, Victim);

StartWeaponForwards()
{
	g_WeaponGiven = CreateGlobalForward("WXF_OnWeaponGiven", ET_Ignore, Param_Cell, Param_Cell);
	g_WeaponRemoved = CreateGlobalForward("WXF_OnWeaponRemoved", ET_Ignore, Param_Cell, Param_Cell);
	g_WeaponFired = CreateGlobalForward("WXF_OnWeaponFired", ET_Ignore, Param_Cell, Param_Cell);
	g_WeaponDamaged = CreateGlobalForward("WXF_OnWeaponDamaged", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
	g_WeaponKilled = CreateGlobalForward("WXF_OnWeaponKilled", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
}

public Native_RegisterWeapon(Handle:plugin, numParams)
{
	decl String:replace[32];
	decl String:name[32];
	GetNativeString(1, replace, sizeof(replace));
	GetNativeString(2, name, sizeof(name));
	
	new WeaponID = RegisteredWeapons;
	WeaponReplaceClass[WeaponID] = replace;
	WeaponName[WeaponID] = name;
	WeaponViewModel[WeaponID] = -1;
	WeaponWorldModel[WeaponID] = -1;
	
	RegisteredWeapons++;
	return WeaponID;
}
public Native_GetWeaponReplaceClass(Handle:plugin, numParams)
{
	new WeaponID = GetNativeCell(1);
	decl String:buffer[32];
	
	strcopy(buffer,sizeof(buffer),WeaponReplaceClass[WeaponID]);
	SetNativeString(2, buffer, sizeof(buffer));
}

public Native_GetWeaponName(Handle:plugin, numParams)
{
	new WeaponID = GetNativeCell(1);
	decl String:name[32];
	
	strcopy(name,sizeof(name),WeaponName[WeaponID]);
	SetNativeString(2, name, sizeof(name));
}

public Native_SetWeaponViewModel(Handle:plugin, numParams)
{
	new WeaponID = GetNativeCell(1);
	decl String:path[128];
	
	GetNativeString(2,path,sizeof(path));
	
	//Fixes SteamPipe Bug
	AddFileToDownloadsTable(path);
	
	new ModelIndex = PrecacheModel(path);
	WeaponViewModel[WeaponID] = ModelIndex;
}
public Native_GetWeaponViewModel(Handle:plugin, numParams)
{
	new WeaponID = GetNativeCell(1);
	return WeaponViewModel[WeaponID];
}

public Native_SetWeaponWorldModel(Handle:plugin, numParams)
{
	new WeaponID = GetNativeCell(1);
	decl String:path[128];
	
	GetNativeString(2,path,sizeof(path));
	
	//Fixes SteamPipe Bug
	AddFileToDownloadsTable(path);
	
	new ModelIndex = PrecacheModel(path);
	WeaponWorldModel[WeaponID] = ModelIndex;
}
public Native_GetWeaponWorldModel(Handle:plugin, numParams)
{
	new WeaponID = GetNativeCell(1);
	return WeaponWorldModel[WeaponID];
}

public Native_RegisteredWeapons(Handle:plugin, numParams)
{
	return RegisteredWeapons;
}

public Native_CallForward(Handle:plugin, numParams)
{
	decl Action:result;
	new FID = GetNativeCell(1);
	new Client = GetNativeCell(2);
	new WeaponID = GetNativeCell(3);
	
	if(FID == 0) {Call_StartForward(g_WeaponGiven); Call_PushCell(Client); Call_PushCell(WeaponID); Call_Finish(_:result); return;}
	else if(FID == 1) {Call_StartForward(g_WeaponRemoved); Call_PushCell(Client); Call_PushCell(WeaponID); Call_Finish(_:result); return;}
	else if(FID == 2) {Call_StartForward(g_WeaponFired); Call_PushCell(Client); Call_PushCell(WeaponID); Call_Finish(_:result); return;}
	else if(FID == 3) {Call_StartForward(g_WeaponDamaged); Call_PushCell(Client); Call_PushCell(WeaponID); Call_PushCell(GetNativeCell(4)); Call_Finish(_:result); return;}
	else if(FID == 4) {Call_StartForward(g_WeaponKilled); Call_PushCell(Client); Call_PushCell(WeaponID); Call_PushCell(GetNativeCell(4)); Call_Finish(_:result); return;}
}
public Native_CallForward3(Handle:plugin, numParams)
{
	decl Action:result;
	new FID = GetNativeCell(1);
	new Client = GetNativeCell(2);
	new WeaponID = GetNativeCell(3);
	
	if(FID == 3) {Call_StartForward(g_WeaponDamaged); Call_PushCell(Client); Call_PushCell(WeaponID); Call_PushCell(GetNativeCell(4)); Call_Finish(_:result); return;}
	else if(FID == 4) {Call_StartForward(g_WeaponKilled); Call_PushCell(Client); Call_PushCell(WeaponID); Call_PushCell(GetNativeCell(4)); Call_Finish(_:result); return;}
}



